<?php
define('IN_DICE', true);
define( 'DIR_ROOT', dirname( __FILE__ ) . '/' );

set_time_limit(30);   //设置脚本执行时间
date_default_timezone_set('Asia/Shanghai');//设置时区

require DIR_ROOT . 'cfg/cfg.inc.php'; //加载配置文件
include DIR_MDL . 'base.php'; //加载base

all::setcfg( $cfg ); //设置配置文件
all::$aOut = $aOut; //全局输出变量

include DIR_LIB . 'func.php'; //公共库文件
include DIR_LIB . 'class.page.php'; //分页类

func::header();
func::dp3p();

all::loadlang( all::$cfg['lang'] ); //设置系统默认语言
include DIR_MDL . 'model.php'; //加载model
include DIR_CTL . 'control.php'; //加载控制器基类

$aBrowser = func::getbrowser();
if( empty( $aBrowser ) && isset( $argv ) && count( $argv ) > 1 ) { //从命令行下调用
  $m = $argv[1];
  $a = $argv[2];
} else {
  $m = empty($_REQUEST['m']) ? 'index' : func::input ( 'm' );
  $a = empty($_REQUEST['a']) ? 'index' : func::input ( 'a' );
  if (PRODUCT_ENV === true && $m == 'script') { //生产环境下不允许用浏览器调用定时任务
    //die('Action not found!');
  }
}

if( !S('debug') && $m != 'script' ) {
  include DIR_DAT . 'stop.php'; //加载停机控制文件
}

if( PRODUCT_ENV === true && defined( 'DICE_TEST' ) ) {
  func::showerr( 'Test over!' );
}

include DIR_LIB . 'amfphp/amf/app/Gateway.php';

list($usec, $sec) = explode(" ", microtime());
$amfphp['startTime'] = ((float) $usec + (float) $sec);

$servicesPath = DIR_CTL;
$voPath = DIR_CTL . "vo/";

$gateway = new Gateway();
$gateway->setClassPath($servicesPath);
$gateway->setLooseMode(false);
$gateway->setClassMappingsPath($voPath);
$gateway->setCharsetHandler("none", "ISO-8859-1", "ISO-8859-1");  //数据库UTF-8编码时调这个

$gateway->setErrorHandling(E_ALL ^ E_NOTICE);
if (PRODUCT_ENV === true) { //产品环境关闭调试参数
  $gateway->disableDebug();
  $gateway->setErrorHandling(0);
  //$gateway->disableStandalonePlayer();
}
//$gateway->logIncomingMessages('./in/'); //flash传递过来的参数都会保存到此目录下,通过$HTTP_RAW_POST_DATA或php://input获取
//$gateway->logOutgoingMessages('./out/'); //返回给flash的数据都会保存到此目录下
$gateway->disableNativeExtension(); //禁用服务器amf扩展,如果加载了amfext扩展,由于此扩展有缺陷,就应该调用这个
$gateway->enableGzipCompression(3 * 1024);  //如果设置,则如果数据量大于此数将采取zlib压缩,需要zlib支持.字节为单位
$gateway->service();
